//
//  GameViewModel.swift
//  DouYuZB
//
//  Created by DSDL on 2016/11/4.
//  Copyright © 2016年 鼎商动力. All rights reserved.
//

import UIKit

class GameViewModel{
     lazy var games:[GameModel] = [GameModel]()
}
extension GameViewModel{
    func loadAllGamesData(finishedCallback : @escaping () -> Void) {
        NetworkTools.requestData(.get, URLString: "http://capi.douyucdn.cn/api/v1/getColumnDetail?shortName=game") { (result) in
            // 1.获取数据
            guard let resultDict = result as? [String : Any] else { return }
            guard let dataArray = resultDict["data"] as? [[String : Any]] else { return }
            // 2.字典转模型
            for dict in dataArray {
                self.games.append(GameModel(dict: dict))
            }
            // 3.通知外界数据请求完成
            finishedCallback()
        }
    }
}
